package com.xcalendar.service.rest.impl;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;

import com.xcalendar.database.table.User;
import com.xcalendar.exception.IncorrectNameOrPasswordException;
import com.xcalendar.management.UserManager;
import com.xcalendar.managementImpl.UserManagerImpl;
import com.xcalendar.service.rest.converter.UserConverter;

@Path("/user/")
public class UserResource {

	@GET
	@Produces({ "application/json" })
	@Path("/login/name={userName}&password={password}/")
	public UserConverter getUser(@PathParam("userName") String userName, @PathParam("password") String password) {
		UserManager um = new UserManagerImpl();
		User user = null;
		UserConverter converter;
		try {
			user = um.login(userName, password);
			converter = new UserConverter(user);
		} catch (IncorrectNameOrPasswordException e) {
			converter = new UserConverter();
			converter.setError("Incorrect username Or wrong password !");
		}
		
		return converter;
	}
}